/***************************************************************************
 * Open Object Oriented ANSI C                                             *
 ***************************************************************************
 * Code given under the terms of GNU General Public Licence (GPLv3)        *
 * and without any waranties of any kind including but not limitative to   *
 * waranties on merchandability or any particular applications fitness.    *
 * For more information on GNU/GPL go on :                                 *
 * "http://www.gnu.org/copyleft/gpl.html"                                  *
 *                                                                         *
 * You are allowed to use it for any purposes in the terms of GNU/GPLv3    *
 * (or more).                                                              *
 * This text MUST stay in state on copyed sources (or sources using it)    *
 * and must not be altered.                                                *
 * You are allowed to add your name at the end of the Copylefs list.       *
 ***************************************************************************
 * Copylefts List :                                                        *
 ***************************************************************************
 * 2010-03-20 Patrick PIGNOL <pignol_patrick@hotmail.com> (Original)       *
 * (Type your name here if needed)                                         *
 ***************************************************************************/
#ifndef EXCEPTIONHANDLER_H_INCLUDED
#define EXCEPTIONHANDLER_H_INCLUDED

#define EXCEPTIONHANDLER_TYPEID 5

typedef struct ExceptionHandlerVirtualTable ExceptionHandlerVirtualTable;
typedef struct ExceptionHandlerInterface ExceptionHandlerInterface;
typedef struct ExceptionHandler ExceptionHandler;

#include "Exception.h"

/*Sealed*/

struct ExceptionHandlerVirtualTable
{
    unsigned long int TypeID;
    ClassInterface* Interface;
    ClassVirtualTable* AncestorTable;
    unsigned long int ReferenceCount;
    ExceptionHandler* (*new)(unsigned long pArgsCount, va_list* pParameters);
    ExceptionHandlerVirtualTable* (*Initialize)(ExceptionHandler* this, unsigned long pArgsCount, va_list* pParameters);
    void (*Garbage)(ExceptionHandler* this);
    unsigned long int (*TypeOf)(ExceptionHandler* this);
    bool (*IsSameTypeThanTypeID)(ExceptionHandler* this, unsigned long int pTypeID);
    bool (*IsKindOfTypeID)(ExceptionHandler* this, unsigned long int pTypeID);
    bool (*IsSameTypeThan)(ExceptionHandler* this, Class* pSource);
    bool (*IsKindOf)(ExceptionHandler* this, Class* pSource);
};

struct ExceptionHandler
{
    ExceptionHandlerVirtualTable* VirtualTable;
    void (*Constructor)(ExceptionHandler* this, unsigned long int pArgsCount, va_list* pParameters);
    void (*Destructor)(ExceptionHandler* this);
    ExceptionHandler* (*Clone)(ExceptionHandler* this);
    Class* aTargetObject;
    unsigned long int aExceptionTypeID;
    void (*aHandler)(Class* pTarget, Exception* pException, unsigned long int pArgsCount, va_list* pParameters);
    unsigned long int (*ExceptionTypeIDHandler)(ExceptionHandler* this);
    void (*Handle)(ExceptionHandler* this, Exception* pException, unsigned long int pArgsCount, va_list* pParameters);
};

ExceptionHandler* ExceptionHandlerNew(unsigned long pArgsCount, va_list* pParameters);
ExceptionHandlerVirtualTable* ExceptionHandlerInitialize(ExceptionHandler* this, unsigned long pArgsCount, va_list* pParameters);
void ExceptionHandlerConstructor(ExceptionHandler* this, unsigned long int pArgsCount, va_list* pParameters);
void ExceptionHandlerDestructor(ExceptionHandler* this);
ExceptionHandler* ExceptionHandlerClone(ExceptionHandler* this);
unsigned long int ExceptionHandlerExceptionTypeIDHandler();
void ExceptionHandlerHandle(ExceptionHandler* this, Exception* pException, unsigned long int pArgsCount, va_list* pParameters);
#endif /* EXCEPTIONHANDLER_H_INCLUDED*/
